// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
//
// ███╗   ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
// ████╗  ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
// ██╔██╗ ██║██║   ██║   ██║   ██║██║     █████╗
// ██║╚██╗██║██║   ██║   ██║   ██║██║     ██╔══╝
// ██║ ╚████║╚██████╔╝   ██║   ██║╚██████╗███████╗
// ╚═╝  ╚═══╝ ╚═════╝    ╚═╝   ╚═╝ ╚═════╝╚══════╝
// ------------------------------------------------
//
// This file is automatically generated.
// Please do not edit these files manually.
//
// ------------------------------------------------

#nullable restore

using Elastic.Clients.Elasticsearch.Fluent;
using Elastic.Clients.Elasticsearch.Serialization;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Elastic.Clients.Elasticsearch.Aggregations;

public sealed partial class TimeSeriesAggregation
{
	/// <summary>
	/// <para>
	/// Set to <c>true</c> to associate a unique string key with each bucket and returns the ranges as a hash rather than an array.
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("keyed")]
	public bool? Keyed { get; set; }

	/// <summary>
	/// <para>
	/// The maximum number of results to return.
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("size")]
	public int? Size { get; set; }

	public static implicit operator Elastic.Clients.Elasticsearch.Aggregations.Aggregation(TimeSeriesAggregation timeSeriesAggregation) => Elastic.Clients.Elasticsearch.Aggregations.Aggregation.TimeSeries(timeSeriesAggregation);
}

public sealed partial class TimeSeriesAggregationDescriptor : SerializableDescriptor<TimeSeriesAggregationDescriptor>
{
	internal TimeSeriesAggregationDescriptor(Action<TimeSeriesAggregationDescriptor> configure) => configure.Invoke(this);

	public TimeSeriesAggregationDescriptor() : base()
	{
	}

	private bool? KeyedValue { get; set; }
	private int? SizeValue { get; set; }

	/// <summary>
	/// <para>
	/// Set to <c>true</c> to associate a unique string key with each bucket and returns the ranges as a hash rather than an array.
	/// </para>
	/// </summary>
	public TimeSeriesAggregationDescriptor Keyed(bool? keyed = true)
	{
		KeyedValue = keyed;
		return Self;
	}

	/// <summary>
	/// <para>
	/// The maximum number of results to return.
	/// </para>
	/// </summary>
	public TimeSeriesAggregationDescriptor Size(int? size)
	{
		SizeValue = size;
		return Self;
	}

	protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
	{
		writer.WriteStartObject();
		if (KeyedValue.HasValue)
		{
			writer.WritePropertyName("keyed");
			writer.WriteBooleanValue(KeyedValue.Value);
		}

		if (SizeValue.HasValue)
		{
			writer.WritePropertyName("size");
			writer.WriteNumberValue(SizeValue.Value);
		}

		writer.WriteEndObject();
	}
}